With the Managed Resource License Store, you embed your license key into one of the assemblies that your application comprises of.
This functionality is not available under (or the text does not apply to) COM development platform.
The main advantage of this method is that it does not require any additional actions during deployment. Also, because the Managed Resource License is the first one in the search order, you have a guarantee that if you properly place a specific valid license key into the managed resource license store, it will be the one actually used - it cannot be changed by License Manager, for example. The disadvantage of this method is that you need to put extra code and data into your application, before building it.
Concepts
Follow the steps below in order to place a license into the Managed Resource License Store and use it. The procedure is written for C# in Visual Studio, but should be similar with other managed languages and tools.
- Place the license key file into your project. To do so, pick a folder in your project, and in Solution Explorer, right-click on it and select -> . Then, select your license key file; this is the file that has been given to you with QuickOPC or OPC Wizard purchase. It has .BIN or .TXT extension, and its name usually starts with a "Key-Permanent-...". Press Add in order to finalize the selection.
- Turn the license key file in your project to an embedded resource: Select the file in Solution Explorer. Then, in the Properties window, select the Build Action row. Click on the drop-down button on its right side and select "Embedded Resource" from the list; alternatively, use up and down keys to make the same selection.
- Register the managed resource of the license key: At the beginning of your code, before you call any QuickOPC or OPC Wizard operations, obtain the static Instance Field from the LicensingManagement Class, and call the RegisterManagedResource Method or RegisterManagedResourceWithExistenceCheck Method with appropriate arguments. For QuickOPC license key, the first two arguments should always be "QuickOPC" and "Multipurpose". For OPC Wizard license key, the first two arguments should always be "OPCWizard" and "Multipurpose". The third argument determines the assembly where the license key resides; you would typically use the Assembly.GetExecutingAssembly Method here, if the resource is in the same assembly as the code that is calling the RegisterManagedResource Method or RegisterManagedResourceWithExistenceCheck Method. The fourth argument is the namespace-qualified name of the managed resource. Visual Studio determines the namespace by concatenating the default namespace (as given in project properties) with names of the project folders (starting from the project root) the embedded resource resides in. So for example, if your default namespace is MyApp, and you have placed the embedded resource with license key (named "Key-Permanent-ShareIt-1912345678-20180612.txt") to the Resources folder, the namespace-qualified name of the managed resource will be "MyApp.Resource.Key-Permanent-ShareIt-1912345678-20180612.txt". If you are unsure, use the ILDASM tool.
The available registration methods differ as follows:
- The RegisterManagedResource Method does not check the existence of the specified managed resource at the time it is called. It is a bit faster in execution, but makes it more difficult to find errors in resource naming.
- The RegisterManagedResourceWithExistenceCheck Method performs an additional check, testing whether the specified managed resource exists. It throws an exception if the resource does not exist or is not accessible.
The componentName and licenseId arguments of the LicensingManagement.RegisterXXXX methods are case-insensitive.
The license key registration call must be made before any QuickOPC or OPC Wizard operation is performed, or before you attempt to retrieve the license info.
Note that the actual validity of the license key is not checked at the time when the location is registered.
Resource Name Pattern Matching
The proper determining of the managed resource namespace, and precise typing of license key file name is a common source of errors (see Troubleshooting further below). In order to alleviate such problems, you can use a resource name pattern instead of the precise resource name. The pattern uses syntax similar to the Visual Basic LIKE operator. Most importantly, you can use the asterisk ('*') widcard to represent any sequence of characters. For example, instead of passing "MyApp.Resource.Key-Permanent-ShareIt-1912345678-20180612.txt" to the RegisterManagedResource Method or the RegisterManagedResourceWithExistenceCheck Method as the resource name, pass the recommended pattern "*.Key-*.*" instead. This pattern specifies that a manage resource should be located whose full name starts with any sequence of characters (and therefore it can be in any namespace), contains "Key-" followed by any sequence of characters, and has any extension.
The specified pattern must not match more than one managed resource in the assembly, otherwise an error occurs.
The disadvantage of using the name pattern is a (slight) risk that other managed resources that happen to match the specified pattern will be found, but since you are normally in control of what managed resources go into your project, the risk can easily be mitigated.
Examples
The example below shows how to register a license located in an embedded managed resource.
The example below shows how to register a license located in an embedded managed resource.
Example: Examples - Server Licensing - Register managed resource
Example: Examples - Server Licensing - Register managed resource and verify existence
Troubleshooting
If you use the RegisterManagedResource Method and the registration is not done properly, the component will continue the search for the license key in the order described in Licensing Elements. Usually, you will end up with a trial license instead, which is manifested by receiving a serial number other than the serial number of the license key you attempted to register. The serial number of stock demo or trial license is between 1111110000 and 1111119999 - see Examples - Client Licensing - Obtain serial number or Examples - Server Licensing - Obtain serial number.
If you use the RegisterManagedResourceWithExistenceCheck Method and the registration is not done properly, an exception is thrown.
Here are the common reasons that can cause these issues:
- Your license key file is included in the project, but its Build Action (in Properties) is not set to "Embedded Resource". This happens easily, because (in Visual Studio) the file looks the same in Solution Explorer; the difference is just a subtle setting visible after you click on the file node in the Solution Explorer and inspect its Properties.
- The actual namespace of the managed resource does not match the one used with the RegisterManagedResource Method. This happens easily, because the actual namespace is determined using the default project namespace and a path of project folders in the solution, which is not always apparent, and there is no direct way (in Visual Studio) to check the resulting namespace.
- You made a typo in the license key file name.
- You have attempted to make a QuickOPC or OPC Wizard operation, or retrieve the license info, before registering the managed resource.
If you cannot rule out that the cause is in incorrect resource namespace (or resource name, in general), we recommend to use the ILDASM tool (IL Disassembler, https://docs.microsoft.com/en-us/dotnet/framework/tools/ildasm-exe-il-disassembler ) to figure out the precise actual name of your license key managed resource. You can use following steps:
- Start Developer Command Prompt for Visual Studio.
- Change current directory to the directory where the resulting assembly of your program resides (using the CD command).
- Type ILDASM PEfilename , where PEFilename is the name of your assembly file (including file extension, typically .DLL or .EXE).
- In the IL DASM window, double-click on the MANIFEST node.
- In the MANIFEST window, find the license key managed resource and verify its namespace and name with the string used in the call to the RegisterManagedResource Method. Sometimes the differences are slight and not apparent at the first site; if you do not find a difference, we recommend that you copy the relevant part of the text from the MANIFEST window into your .NET source code.
For illustration, the part of the MANIFEST with the license key for our example looks like this:
.mresource public 'UADocExamples.Licensing.Key-DemoOrTrial-WebForm-1999003494-20180611.bin'
{
// Offset: 0x00000000 Length: 0x00000A68
}
You will also end up with a trial license if the managed resource registration is made correctly, but the license key is not valid for some reason - for example, it does not apply to the version of the software you are runing.
See Also
Examples - Client Licensing
Examples - Server Licensing